<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学习状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择学习状态" clearable>
          <el-option
            v-for="dict in dict.type.learning_study_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="leaningUserList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="发布人" align="center" prop="publisherName" />
      <el-table-column label="发布时间" align="center" prop="publishTime" />
      <el-table-column label="学习状态" align="center" prop="status">
        <template slot-scope="scope">
          {{scope.row.status == 0 ? '待学习' : '已学习'}}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            :icon="'el-icon-view'"
            @click="handleDetail(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import {getMyList} from "@/api/examine/leaningUser";

  export default {
    name: "LeaningUser",
    dicts: ['learning_study_status'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 用户学习记录表格数据
        leaningUserList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          status: null,
          title: ''
        },
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询用户学习记录列表 */
      getList() {
        this.loading = true;
        getMyList(this.queryParams).then(response => {
          this.leaningUserList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.userId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 修改按钮操作 */
      handleDetail(row) {
        this.$router.push({path: "/learning/myDetail",query: {id: row.contentId}});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('examine/leaningUser/export', {
          ...this.queryParams
        }, `leaningUser_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
